package cn.itcast.user.web;

import cn.itcast.user.pojo.User;
import cn.itcast.user.service.PatternProperties;
import cn.itcast.user.service.UserService;

import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@RestController
@RequestMapping("/user")
@RefreshScope
public class UserController {

    @Autowired
    private UserService userService;

    @Value("${server.port}")
    private Long port;
//
//    @Value("${pattern.dateformat}")
//    private String dateformat;
    @Autowired
    private PatternProperties patternProperties;
    /**
     * 路径： /user/110
     *
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id) {

        User user = userService.queryById(id);

        user.setId(port);

        return user;
    }

    @RequestMapping("/hello")
    public String hello(){

        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(patternProperties.getDateformat()));
//        return "666";
//        return patternProperties.getDateformat();
    }

    @RequestMapping("/ual")
    public PatternProperties ual(){
        return patternProperties;
    }



}
